using System;
using System.Collections;
class Env
{
    protected static string fmtNameValue = "  {0} {1}.";
    private static void AllVariables(EnvironmentVariableTarget tgt)
    {
        string value;
        string key;

        foreach (DictionaryEntry de in Environment.GetEnvironmentVariables(tgt))
        {
            key = (string)de.Key;
            value = (string)de.Value;
            //if (key.Contains(myVarSuffix))
            Console.WriteLine(fmtNameValue, key, value);
        }
    }
    public static void CheckAllVariables()
    {
        //Console.WriteLine("Process:");
        //AllVariables(EnvironmentVariableTarget.Process);

        //Console.WriteLine("User:");
        //AllVariables(EnvironmentVariableTarget.User);

        Console.WriteLine("Machine:");
        AllVariables(EnvironmentVariableTarget.Machine);
    }
    public void Append(string varible, string value1)
    {
        string oldValue = Environment.GetEnvironmentVariable(varible, EnvironmentVariableTarget.Machine);
        if (oldValue == null)
        {
            Environment.SetEnvironmentVariable(varible, @".;", EnvironmentVariableTarget.Machine);
            oldValue = Environment.GetEnvironmentVariable(varible, EnvironmentVariableTarget.Machine);
        }
        string newValue;
        if (!oldValue.Contains(Environment.ExpandEnvironmentVariables(value1)))
        {
            newValue = oldValue + Environment.ExpandEnvironmentVariables(value1);
            Environment.SetEnvironmentVariable(varible, newValue, EnvironmentVariableTarget.Machine);
        }
    }
    public static string ClassPath()
    {
        string strClassPath = Environment.GetEnvironmentVariable(@"classpath");
        if (strClassPath != null)
        {
            return Environment.ExpandEnvironmentVariables(strClassPath);
        }
        return null;        
    }
};